package cn.bitkit.mybatis.builder;

import cn.bitkit.mybatis.CriteriaHandler;
import cn.bitkit.mybatis.SqlCommonHandler;
import cn.bitkit.mybatis.base.BaseSqlBuilder;
import cn.bitkit.mybatis.entity.EntityClass;

import java.util.Map;
import java.util.StringJoiner;

/**
 * @author changbo
 */
public class UpdateNonNullByIdListBuilder implements BaseSqlBuilder {

	@Override
	public String build(EntityClass entityClass, Map<String, Object> paramMap) {
		StringJoiner sql = new StringJoiner(" \n");
		sql.add("UPDATE " + entityClass.getTableName());
		sql.add("SET " + SqlCommonHandler.updateNonNull(entityClass, paramMap.get("entity")));
		sql.add("WHERE " + entityClass.getId().getColumn()+" IN");
		sql.add("(" + CriteriaHandler.initList(paramMap) + ")");
        return sql.toString();
	}

}
